import Cookies from 'js-cookie'
import axios from 'axios'
import qs from 'qs'
import { getUUID } from '@/utils'
import moment from 'moment'
import { debounce } from 'lodash'
import CONFIG from '@/utils/config'
import { updateCommunityReport } from '@/api/new'
import config from "@/utils/config";
import {filterRole} from '@/utils/common'
export default {
  data() {
    return {
      mixinViewModuleOptions: {
        createdIsNeed: true,
        activatedIsNeed: false,
        getDataListURL: '',
        getDataListIsPage: false,
        deleteURL: '',
        deleteIsBatch: false,
        deleteIsBatchKey: 'id',
        exportURL: '',
        disabledBatchURL: '',
        disabledIsBatch: false,
        disabledIsBatchKey: 'id'
      },
      dataForm: {},
      dataList: [],
      pageTotal: 0,
      size: 100,
      current: 1,
      connectorSetting: {},
      order: '',
      orderField: '',
      page: 1,
      limit: 10,
      total: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: true,
      linkWidgetVisible: true,
      gridDefaultSetting: {
        allowResizing: true,
        allowFiltering: true,
        showColumnMenu: true,
        filterSettings: {
          type: 'Excel'
        },
        allowGrouping: false,
        allowPaging: false,
        toolbar: ['Search', 'ColumnChooser'],
        allowExcelExport: true,
        allowPdfExport: true,
        showColumnChooser: true,
        groupOptions: {
          columns: ['name']
        },
        allowReordering: true,
        allowSorting: true,
        allowTextWrap: true,
        height: window.innerHeight - 230,
        selectOptions: {
          type: 'Multiple'
        },
        pageSettings: {
          pageSize: 100,
          pageSizes: [10, 50, 100, 200, 1000],
          pageCount: 4
        },
        groupSettings: {
          allowReordering: false,
          columns: [],
          disablePageWiseAggregates: false,
          enableLazyLoading: false,
          showDropArea: true,
          showGroupedColumn: false,
          showToggleButton: false
        }
      },
      pageOptions: {
        currentPage: 1,
        pageSize: 10,
        pageSizes: [10, 50, 100, 200],
        total: 0,
        layout: 'total, sizes, prev, pager, next, jumper'
      },
      resourceType: {
        '/Widgets': 1,
        '/Dashboards': 0,
        '/Scorecards': 2,
        '/Slicer': 3,
        '/Bots': 4
      },
      keyWordsValue: '',
      isChangeKeyWords: false
    }
  },
  created() {
    if (
      this.dashboardType === 'Internal Dashboards' ||
      this.dashboardType === 'Internal Scorecard'
    ) {
      this.$set(this.dataForm, 'internal', true)
    }
    if (
      this.dashboardType === 'Scorecard Dashboards' ||
      this.dashboardType === 'Internal Scorecard'
    ) {
      this.$set(this.dataForm, 'layoutType', 'scorecard_layout')
    }
    if (this.mixinViewModuleOptions.createdIsNeed) {
      if (this.viewValue) {
        if (this.viewValue === 'Grid') {
          if (this.recordFilterType) {
            this.query({
              businessType: this.recordFilterType
            })
          } else this.query()
        }
        if (
          this.viewValue === 'List' &&
          this.mixinViewModuleOptions.getDataListURLCard
        ) {
          // this.cardQuery()
        }
      } else {
        if (this.recordFilterType) {
          this.query({
            businessType: this.recordFilterType
          })
        } else this.query()
      }
    }
  },
  watch: {
    // viewValue (val) {
    //   if (this.mixinViewModuleOptions.createdIsNeed) {
    //     if (this.viewValue) {
    //       if (this.viewValue === 'Grid') {
    //         this.query()
    //       } else if (this.viewValue === 'List' && this.mixinViewModuleOptions.getDataListURLCard) {
    //         this.cardQuery()
    //       } else {
    //         this.query()
    //       }
    //     } else this.query()
    //   }
    // }
  },
  activated() {
    // if (this.mixinViewModuleOptions.activatedIsNeed) {
    //   this.query()
    // }
  },

  methods: {
    keyWordsChange: debounce(function (val) {
      if (this.keyWordsValue === val.trim()) {
        return false
      }
      this.isChangeKeyWords = true
      this.keyWordsValue = val.trim()
      // if (this.$refs.cardList) if (this.$refs.cardList) this.$refs.cardList.scrollTop()
      // if (this.$refs.cardList) {
      //   this.$refs.cardList.currentPage = 1
      // }
      this.cardQuery()
    }, 1000),
    shareHandle(item) {
      let url =
        window.location.origin +
        `/publicReport?pageid=${item.id}&name=${item.name}`
      this.$nextTick(() => {
        this.$refs['share-link'].init(item, url)
      })
    },
    doDelete(id, row) {
      const params = {
        id: id
      }
      this.$interface.reports
        .delReportSetting(params)
        .then(async ({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          if (!this.isUserCloneTemplate) {
            if (this.viewValue === 'List') {
              const { removeFavorite } = this.$interface.reports
              if (row.isFavorite) {
                try {
                  await removeFavorite(id, row.favoritesType).then()
                } catch (e) {}
              }
              this.$refs['quick-filter'].getQuickFilters('integration')
              this.cardQuery()
            } else {
              this.query()
            }
            return this.$message.success(res.msg)
          }
        })
    },
    deleteHandleItem(row) {
      if (this.isUserCloneTemplate) {
        this.doDelete(row.id, row)
      } else {
        this.$confirm(
          this.$t('custom.widget.deleteconfirm'),
          this.$t('custom.widget.deleteTitle'),
          {
            confirmButtonText: this.$t('confirm'),
            cancelButtonText: this.$t('cancel'),
            // type: 'warning',
            dangerouslyUseHTMLString: true
          }
        )
          .then(() => {
            this.doDelete(row.id, row)
          })
          .catch(() => {})
      }
    },
    async getWidget (gadgetId) {
      const { getReportSettingInfo } = this.$interface.reports
      const params = {
        gadgetId,
        includeSql: true
      }
      const { data: response } = await getReportSettingInfo(params)
      if (response.code !== 0) {
        throw response.msg
      }
      return response.data || {}
    },
    async userTemplateClone(row) {
      const { roleIdList } = await this.getWidget(row.i)
      const params = {
        id: row.id,
        name:
          row.name ||
          row.widgetName +
            ' Clone_' +
            moment().utc().format('YY/MM/DD HH:mm:ss'),
        tenantCode: this.$store.state.user.tenantCode,
        businessType: 'Custom',
        status: 'Published',
        roleIdList: await filterRole(roleIdList)
      }
      params.gadgetId = getUUID()
      this.dataListLoading = true
      this.$interface.reports
        .postWidgetCloneDataApi(params)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            this.dataListLoading = false
            return this.$message.error(res.msg)
          }
          if (res.data) {
            this.queryModelDefaultSetting.dataInfo.businessId =
              res.data.businessId
            this.queryModelDefaultSetting.dataInfo.businessType =
              res.data.businessType
            this.queryModelDefaultSetting.dataInfo.gadgetId = res.data.gadgetId
            this.queryModelDefaultSetting.dataInfo.gadgetType =
              res.data.gadgetType
            this.queryModelDefaultSetting.dataInfo.gadgetSetting =
              res.data.gadgetSetting
            this.$nextTick(() => {
              this.$store.state.isWidget = true
              this.showQueryModel()
              this.dataListLoading = false
            })
          }
        })
        .catch(() => {
          this.flag = true
        })
      // }
    },
    commandClick(e) {
      if (e.commandColumn.type === 'Edit') {
        this.addOrUpdateHandle(e.rowData.id)
      }
      if (e.commandColumn.type === 'Delete') {
        this.deleteHandle(e.rowData.id)
      }
    },
    queryType() {
      let temp = null
      if (this.$store.state.app.contentIsNeedRefreshCache) {
        temp = 'REFRESHCACHE'
      }
      this.$store.commit('SET_CONTENT_IS_NEED_REFRESH_CACHE', false)
      return temp
    },
    // commandClick (type, row) {
    //   if (type === 'Edit') {
    //     this.addOrUpdateHandle(row.id)
    //   }
    //   if (type === 'Delete') {
    //     this.deleteHandle(row.id)
    //   }
    // },
    query(tabParams) {
      if (this.grid) {
        return
      }
      if (String(this.httpEnd) !== 'undefined') this.httpEnd = true
      this.dataList = []
      this.dataListLoading = true
      var _self = this
      if (!this.mixinViewModuleOptions.getDataListURL) return
      // if (this.IsSlicer()) this.dataForm.showAllIntegration = true
      this.$http
        .get(this.mixinViewModuleOptions.getDataListURL, {
          params: {
            order: this.order,
            orderField: this.orderField,
            page: this.mixinViewModuleOptions.getDataListIsPage
              ? this.page
              : null,
            limit: this.mixinViewModuleOptions.getDataListIsPage
              ? this.limit
              : null,
            queryType: this.queryType(),
            ...this.dataForm,
            ...tabParams
            // type: this.IsSlicer() ? 2 : 1
          }
        })
        .then(({ data: res }) => {
          if (String(this.httpEnd) !== 'undefined') this.httpEnd = false
          if (res.code !== 0) {
            this.dataList = []
            this.pageOptions.total = 0
            return this.$message.error(res.msg)
          }
          if (
            _self.mixinViewModuleOptions.getDataListURL ===
            '/web/bots/sys/bot/list-integration'
          ) {
            let temp = []
            res.data.forEach(item => {
              temp.push({
                ...item,
                cardAlertLoading: false,
                cardEnableLoading: false,
                cardEscalationLoading: false
              })
            })
            _self.dataList = temp
          } else {
            this.dataList = this.mixinViewModuleOptions.getDataListIsPage
              ? res.data.list
              : res.data
            if (this.hasOwnProperty('billableUserCount')) {
              try {
                if (this.getManageUserList) {
                  this.getManageUserList()
                }
                const data = this.mixinViewModuleOptions.getDataListIsPage
                  ? res.data.list
                  : res.data
                if (this.dataForm.status === 1) {
                  this.billableUserCount = data.filter(item => {
                    const roleIdList = item.roleList.map(item => item.id)
                    return  item.status === 1 && ( this._.intersection(config.freeUserRole, roleIdList).length === 0 || roleIdList.includes(config.attendanceOnlyId))
                  }).length
                }
              } catch (e) {}
            }
            this.queryCount = false
          }
          try {
            this.dataList.forEach(item => {
              item.integrationForSort = item.integration.join(',')
              for (var key in item) {
                if (key === 'integration') {
                  item[key] = item[key].join(',')
                }
              }
            })
          } catch (error) {}
          this.connectorSetting = this.mixinViewModuleOptions.getDataListIsPage
            ? res.data.setting
            : {}
          this.pageOptions.total = this.mixinViewModuleOptions.getDataListIsPage
            ? res.data.total
            : 0
        })
        .catch(() => {
          if (String(this.httpEnd) !== 'undefined') this.httpEnd = false
          this.dataList = []
        })
        .finally(() => {
          this.dataListLoading = false
        })
    },
    IsSlicer() {
      let path = window.location.pathname
      if (path === '/Slicer') {
        return true
      } else {
        return false
      }
    },
    refreshQuickFilter() {
      this.$store.dispatch('changeQuickFilter', new Date().getTime())
    },
    cardQuery(size, current, isQuickFilter) {
      if (size) {
        this.size = size
      }
      if (current) {
        this.current = current
      }
      if (isQuickFilter) {
        this.size = 100
        this.current = 1
      }
      if (!size && this.$route.path === '/portal') {
        this.size = 10
      }
      if (this.isChangeKeyWords) {
        this.current = 1
      }
      // if (this.dataListLoading || !this.mixinViewModuleOptions.getDataListURLCard) return false
      this.dataListLoading = true
      this.dataList = []

      let CancelToken = axios.CancelToken
      // if (this.IsSlicer()) this.dataForm.showAllIntegration = true
      var _self = this
      let params = {
        ...this.filterProject,
        orderField: this.orderField,
        page: this.mixinViewModuleOptions.getDataListIsPage ? this.page : null,
        limit: this.mixinViewModuleOptions.getDataListIsPage
          ? this.limit
          : null,
        queryType: this.queryType(),
        ...this.dataForm,
        // type: this.IsSlicer() ? 2 : 1,
        size: this.size,
        current: this.current,
        name: this.keyWordsValue
      }
      params = JSON.parse(JSON.stringify(params))
      if (params.filter.shared) {
        params.filter.shared = params.filter.shared.replace(/\s+/g, '')
        if (this.selectedQuickFilter.id.includes('Template')) {
          params.filter.shared = `t${params.filter.shared}`
        }
      }
      if (String(this.resourceType[this.$route.path])) {
        params.resourceType = this.resourceType[this.$route.path]
      }
      if (params.layoutType && params.layoutType === 'scorecard_layout') {
        params.resourceType = 2
      }
      if (params.layoutType && params.layoutType === 'report_layout') {
        params.resourceType = 0
      }
      if (this.isReportAdd) {
        params.resourceType = 0
      }
      if (this.isSlicer) {
        params.resourceType = 3
      }
      if (this.resourceTypeId) {
        params.resourceType = this.resourceTypeId
      }
      if(this.datasetResourceType) {
        params.resourceType = this.datasetResourceType
      }
      params = JSON.parse(JSON.stringify(params))
      if (
        this.selectedQuickFilter &&
        this.selectedQuickFilter.id === 'my-Favorites'
      ) {
        params.myFavorite = true
      }
      if (this.$route.path === '/Dashboards') {
        if (
          params.filter.type.includes('Template') &&
          !params.filter.type.includes('Community')
        ) {
          params.filter.excludeSubLevelType = 100101
          if (params.filter.subLevelType) {
            delete params.filter.subLevelType
          }
        } else if (params.filter.type.includes('Community')) {
          params.filter.subLevelType = 100101
          const num = params.filter.type.indexOf('Community')
          params.filter.type.splice(num, 1)
        } else {
          if (params.filter.subLevelType) {
            delete params.filter.subLevelType
          }
        }
      }
      try {
        if (
          params.filter.modelNum.min === 0 &&
          params.filter.modelNum.max === 0
        ) {
          params.filter.modelNum.min = ''
          params.filter.modelNum.max = ''
        }
      } catch (e) {}
      this.$http
        .post(
          this.mixinViewModuleOptions.getDataListURLCard,
          params,
          {
            cancelToken: new CancelToken(function executor(c) {
              window.CardListSource = c
            })
          },
          { cache: { enable: false } }
        )
        .then(({ data: res }) => {
          if (res.code !== 0) {
            this.pageTotal = 0
            this.dataList = []
            this.pageOptions.total = 0
            return this.$message.error(res.msg)
          }
          if (res.data) {
            this.isChangeKeyWords = false
            this.pageTotal = res.data.total || 0
            this.size = res.data.size || 100
            this.current = res.data.current || 1
            if (res.data.records) {
              if (
                _self.mixinViewModuleOptions.getDataListURLCard ===
                '/web/bots/sys/bot/card-list'
              ) {
                let temp = []
                res.data.records.forEach(item => {
                  temp.push({
                    ...item,
                    cardAlertLoading: false,
                    cardEnableLoading: false,
                    cardEscalationLoading: false
                  })
                })
                _self.dataList = temp
              } else {
                _self.dataList = res.data.records
              }
            }
            
          try {
            this.dataList = this.dataList.map(i=>{
              return {
                ...i,
                resourceName: i.name,
                resourceId: i.id
              }
            })
          } catch (error) {
            
          }
            this.connectorSetting = this.mixinViewModuleOptions
              .getDataListIsPage
              ? res.data.setting
              : {}
            this.pageOptions.total = this.mixinViewModuleOptions
              .getDataListIsPage
              ? res.data.total
              : 0

            this.dataListLoading = false
          }
        })
        .catch(thrown => {
          if (!axios.isCancel(thrown) && thrown.message !== 'Request aborted') {
            this.dataListLoading = false
          }
        })
    },
    dataListSelectionChangeHandle() {
      if (this.$refs.grid)
        this.dataListSelections = this.$refs.grid.getSelectedRecords()
    },
    dataListSortChangeHandle(data) {
      if (!data.order || !data.prop) {
        this.order = ''
        this.orderField = ''
        return false
      }
      this.order = data.order.replace(/ending$/, '')
      this.orderField = data.prop.replace(/([A-Z])/g, '_$1').toLowerCase()
      this.query()
    },
    // pageSizeChangeHandle (val) {
    //   this.page = 1
    //   this.limit = val
    //   this.query()
    // },
    // pageCurrentChangeHandle (val) {
    //   this.page = val
    //   this.query()
    // },
    getDataList: function (cardUrl) {
      this.page = 1
      // Todo
      this.$store.commit('REFRESHBOTLIST', 'noFefresh')
      if (this.viewValue && this.viewValue === 'List') {
        // if (this.mixinViewModuleOptions.getDataListURLCard || cardUrl) {
        if (this.$refs.ListReports) {
          this.$refs.ListReports.cardQuery()
        } else if (this.$refs.listDataset) {
          this.$refs.listDataset.cardQuery()
        } else if (this.$refs.ListWidgets) {
          this.$refs.ListWidgets.cardQuery()
        } else if (this.$refs.ListBot) {
          this.refreshQuickFilter()
        } else {
          this.cardQuery()
        }
      } else if (this.viewValue && this.viewValue === 'Grid') {
        this.query()
      } else {
        this.query()
      }
    },
    addOrUpdateHandle (id, isAgent, activeTab) {
      this.addOrUpdateVisible = true
      this.userModalVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init(isAgent, activeTab)
      })
    },
    pagChangeHandle(e) {
      if (e) {
        this.pageOptions.currentPage = e
        this.query()
      }
    },
    pageSizeChangeHandle(e) {
      if (e) {
        this.pageOptions.currentPage = 1
        this.pageOptions.pageSize = e

        this.query()
      }
    },
    closeCurrentTab(data) {
      var tabName = this.$store.state.contentTabsActiveName
      this.$store.state.contentTabs = this.$store.state.contentTabs.filter(
        item => item.name !== tabName
      )
      if (this.$store.state.contentTabs.length <= 0) {
        this.$store.state.sidebarMenuActiveName =
          this.$store.state.contentTabsActiveName = 'home'
        return false
      }
      if (tabName === this.$store.state.contentTabsActiveName) {
        this.$router.push({
          name: this.$store.state.contentTabs[
            this.$store.state.contentTabs.length - 1
          ].name
        })
      }
    },
    refreshGrid() {
      this.dataList = [...this.dataList]
    },
    async deleteShareToCommunity(item, page) {
      if (item.originalId && item.type === 100101) {
        const res = await this.$interface.reports.getformlistShareData(
          item.originalId
        )

        const delRes = await updateCommunityReport({
          ...this.getDelParams(res.data.data),
          originalId: item.originalId
        })
        if (delRes.data.code === 0) {
          this.$message.success('Success')
          try {
            if (page === 'bot') {
              this.$refs['quick-filter'].getQuickFilters('integration')
              this.cardQuery()
            } else {
              this.$refs['ListReports'].$refs['quick-filter'].getQuickFilters(
                'integration'
              )
              this.$refs.ListReports.cardQuery()
            }
          } catch (err) {}
        } else {
          this.$message.success(delRes.data.msg)
        }
      }
    },
    getDelParams(data) {
      let config = Object.assign({}, data.config)
      config.shareToCommunity.uploadCommunity = false
      this.loading = true
      let params = {
        resourceId: data.resourceId,
        resourceType: data.resourceType,
        resourceUrl: data.resourceUrl,
        expiredNum: data.expiredNum,
        expiredValue: data.expiredValue,
        permissionType: 'user',
        shareToken: data.shareToken,
        copyResourceId: data.copyResourceId,
        config: config
      }
      params.id = data.id
      params.tagType = '3'
      let timeRadio = null
      if (!data.expiredValue && !data.expiredNum) {
        timeRadio = 1
      } else {
        timeRadio = 2
      }
      if (timeRadio === 1) {
        delete params.expiredNum
        delete params.expiredValue
      }
      return params
    },
    deleteHandle(id, row) {
      if (
        this.mixinViewModuleOptions.deleteIsBatch &&
        !id &&
        this.dataListSelections.length <= 0
      ) {
        return this.$message({
          message: this.$t('prompt.deleteBatch'),
          type: 'warning',
          duration: 500
        })
      }
      this.$confirm(
        this.$t('prompt.info', {
          handle: this.$t('delete')
        }),
        this.$t('prompt.title'),
        {
          confirmButtonText: this.$t('confirm'),
          cancelButtonText: this.$t('cancel'),
          type: 'warning'
        }
      )
        .then(() => {
          if (row && row.originalId && row.type === 100101) {
            return this.deleteShareToCommunity(row)
          }
          const requestFunc = () => {
            if (this.mixinViewModuleOptions.deleteURL_other) {
              return this.$http.delete(
                `${this.mixinViewModuleOptions.deleteURL_other}${
                  this.mixinViewModuleOptions.deleteIsBatch
                    ? ''
                    : id + '/delete'
                }`,
                this.mixinViewModuleOptions.deleteIsBatch
                  ? {
                      data: id
                        ? [id]
                        : this.dataListSelections.map(
                            item =>
                              item[this.mixinViewModuleOptions.deleteIsBatchKey]
                          )
                    }
                  : {}
              )
            } else {
              return this.$http.delete(
                `${this.mixinViewModuleOptions.deleteURL}${
                  this.mixinViewModuleOptions.deleteIsBatch ? '' : '/' + id
                }`,
                this.mixinViewModuleOptions.deleteIsBatch
                  ? {
                      data: id
                        ? [id]
                        : this.dataListSelections.map(
                            item =>
                              item[this.mixinViewModuleOptions.deleteIsBatchKey]
                          )
                    }
                  : {}
              )
            }
          }
          requestFunc()
            .then(({ data: res }) => {
              if (res.code !== 0) {
                return this.$message.error(res.msg)
              }
              this.$message({
                message: this.$t('prompt.success'),
                type: 'success',
                duration: 500,
                onClose: async () => {
                  if (this.viewValue === 'List') {
                    if (this.$refs.ListReports) {
                      this.$store.commit(
                        'SET_CONTENT_IS_NEED_REFRESH_CACHE',
                        false
                      )
                      const { removeFavorite } = this.$interface.reports
                      if (row && row.isFavorite) {
                        try {
                          await removeFavorite(id, row.favoritesType).then()
                        } catch (e) {}
                      }
                      this.$refs['ListReports'].$refs[
                        'quick-filter'
                      ].getQuickFilters('integration')
                      this.$refs.ListReports.cardQuery()
                    } else if (this.$refs.listDataset) {
                      this.$refs.listDataset.cardQuery()
                    } else if (this.$refs.ListWidgets) {
                      this.$refs.ListWidgets.cardQuery()
                    } else {
                      this.cardQuery()
                    }
                  } else {
                    this.query()
                  }
                }
              })
            })
            .catch(() => {})
        })
        .catch(() => {})
    },
    exportHandle() {
      var params = qs.stringify({
        token: Cookies.get('token'),
        tenantcode: Cookies.get('tenant_code'),
        ...this.dataForm
      })
      window.location.href = `${window.SITE_CONFIG['apiURL']}${this.mixinViewModuleOptions.exportURL}?${params}`
    },
    disabledBatch(id) {
      const _self = this
      if (
        _self.mixinViewModuleOptions.deleteIsBatch &&
        !id &&
        _self.dataListSelections.length <= 0
      ) {
        return _self.$message({
          message: _self.$t('prompt.disabledBatch'),
          type: 'warning',
          duration: 500
        })
      }
      _self
        .$confirm(
          _self.$t('prompt.info', {
            handle: _self.$t('custom.sys.user.disabledBatch')
          }),
          _self.$t('prompt.title'),
          {
            confirmButtonText: _self.$t('confirm'),
            cancelButtonText: _self.$t('cancel'),
            type: 'warning'
          }
        )
        .then(() => {
          if (
            _self.hasOwnProperty('userBillableVisible') &&
            this.dtoList &&
            this.dtoList.length > 0
          ) {
            _self.userBillableVisible = true
            _self.userBillableType = '2'
            _self.userBillable = '2'
          } else {
            this.disabledBatchResponse(id)
          }
          // _self.dialogVisible = false
          // _self.dataListLoading = true
          // _self.$http.post(
          //   `${_self.mixinViewModuleOptions.disabledBatchURL}${_self.mixinViewModuleOptions.disabledIsBatch ? '' : '/' + id}`,
          //   _self.mixinViewModuleOptions.disabledIsBatch ? {
          //     'userIds': id ? [id] : _self.dataListSelections.map(item => item[_self.mixinViewModuleOptions.disabledIsBatchKey]),
          //     'status': 0
          //   } : {}
          // ).then(({
          //   data: res
          // }) => {
          //   if (res.code !== 0) {
          //     _self.dataListLoading = false
          //     return _self.$message.error(res.msg)
          //   }
          //   _self.dataListLoading = false
          //   _self.$message({
          //     message: _self.$t('prompt.success'),
          //     type: 'success',
          //     duration: 500,
          //     onClose: () => {
          //       _self.query()
          //     }
          //   })
          // }).catch(() => {})
        })
        .catch(() => {})
    },
    disabledBatchResponse(id) {
      const _self = this
      _self.dialogVisible = false
      _self.dataListLoading = true
      _self.$http
        .post(
          `${_self.mixinViewModuleOptions.disabledBatchURL}${
            _self.mixinViewModuleOptions.disabledIsBatch ? '' : '/' + id
          }`,
          _self.mixinViewModuleOptions.disabledIsBatch
            ? {
                userIds: id
                  ? [id]
                  : _self.dataListSelections.map(
                      item =>
                        item[_self.mixinViewModuleOptions.disabledIsBatchKey]
                    ),
                status: 0
              }
            : {}
        )
        .then(({ data: res }) => {
          if (res.code !== 0) {
            _self.dataListLoading = false
            return _self.$message.error(res.msg)
          }
          _self.dataListLoading = false
          if (this.payUserRequest) {
            const { payUser } = this.$interface.pay
            payUser(this.payUserParams).finally(() => {
              this.payUserRequest = false
            })
          }
          _self.$message({
            message: _self.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
              _self.query()
            }
          })
        }).catch(() => {})
        const { alaCarteUpdate } = this.$interface.pay
        alaCarteUpdate({
          userIds: id ? [id] : _self.dataListSelections.map(item => item[_self.mixinViewModuleOptions.disabledIsBatchKey])
        }).then(() => {})
    },
    enabledBatch(id) {
      if (
        this.mixinViewModuleOptions.deleteIsBatch &&
        !id &&
        this.dataListSelections.length <= 0
      ) {
        return this.$message({
          message: this.$t('prompt.enabledBatch'),
          type: 'warning',
          duration: 500
        })
      }
      this.$confirm(
        this.$t('prompt.info', {
          handle: this.$t('custom.sys.user.enabledBatch')
        }),
        this.$t('prompt.title'),
        {
          confirmButtonText: this.$t('confirm'),
          cancelButtonText: this.$t('cancel'),
          type: 'warning'
        }
      )
        .then(() => {
          if (
            this.hasOwnProperty('userBillableVisible') &&
            this.dtoList &&
            this.dtoList.length > 0
          ) {
            this.userBillableVisible = true
            this.userBillableType = '1'
            this.userBillable = '1'
          } else {
            this.enabledBatchResponse(id)
            const { payUser } = this.$interface.pay
            payUser(this.payUserParams).then()
          }
        })
        .catch(() => {})
    },
    enabledBatchResponse(id) {
      this.$http
        .post(
          `${this.mixinViewModuleOptions.disabledBatchURL}${
            this.mixinViewModuleOptions.disabledIsBatch ? '' : '/' + id
          }`,
          this.mixinViewModuleOptions.disabledIsBatch
            ? {
                userIds: id
                  ? [id]
                  : this.dataListSelections.map(
                      item =>
                        item[this.mixinViewModuleOptions.disabledIsBatchKey]
                    ),
                status: 1
              }
            : {}
        )
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          if (this.payUserRequest) {
            const { payUser } = this.$interface.pay
            payUser(this.payUserParams).finally(() => {
              this.payUserRequest = false
            })
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
              this.query()
            }
          })
        })
        .catch(() => {})
    },
    deptChange(e) {
      // this.dataForm.
    }
  }
}
